package com.hbnu.zhanglian.service;

import com.hbnu.zhanglian.dao.UserDAO;
import com.hbnu.zhanglian.entity.User;

public class UserService {
    private UserDAO userDAO = new UserDAO();

    /**
     * 用户注册
     */
    public boolean register(String username, String password) {
        if (username == null || username.trim().isEmpty()) {
            System.out.println("用户名不能为空");
            return false;
        }
        if (password == null || password.trim().isEmpty()) {
            System.out.println("密码不能为空");
            return false;
        }

        User user = new User(username.trim(), password.trim());
        return userDAO.register(user);
    }

    /**
     * 用户登录
     */
    public User login(String username, String password) {
        if (username == null || username.trim().isEmpty() ||
                password == null || password.trim().isEmpty()) {
            System.out.println("用户名或密码不能为空");
            return null;
        }

        return userDAO.login(username.trim(), password.trim());
    }

    /**
     * 更新用户积分
     */
    public boolean updateScore(int userId, int score) {
        return userDAO.updateScore(userId, score);
    }
}